<%@codepage="65001"%>
<%session.codepage="65001"%>
<!-- #include virtual=/inc/dbConn.asp -->
<!-- #include virtual=/inc/function.asp -->
<!-- #include virtual=/inc/action.header.inc.asp -->

<%
	'## 파라미터 변수 선언부
	income		= Request("findIncome")
	accountCd	= Request("findAccountCd")
	compCd		= Request("findCompCd")
	findPart		= Request("findPart")
	mnth		= Request("findMnth")
	keyset	= Request("keyset")
	stDate		= Request("stDate")
	endDate		= Request("endDate")
	
	SQLTitle = "-- ■■■■ 회계(입금) 그리드 List up ■■■■"
	
	'## 검색조건에 따른 조건절 만들기 
	If income <> "" Then 
		addSql = " A.income LIKE '%" & income & "%' "
	End If 
	If accountCd <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND " End If 
		addSql = addSql & " A.accountCd = '" & accountCd & "' "
	End If 
	If findPart <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND " End If 
		addSql = addSql & " A.part = '" & findPart & "' "
	End If 
	If compCd <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND " End If 
		addSql = addSql & " A.compCd = '" & compCd & "' "
	End If 
	If stDate <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND " End If 
		if keyset = "incomeDt" then 
			addSql = addSql & " A.incomeDt >= '" & stDate & "' "
		else
			addSql = addSql & " D." & keyset & " >= '" & stDate & "' "
		end if 
	End If 
	If endDate <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND " End If 
		if keyset = "incomeDt" then 
			addSql = addSql & " A.incomeDt <= '" & endDate & "' "
		else
			addSql = addSql & " D." & keyset & " <= '" & endDate & "' "
		end if 
	End If 
	if mnth <> "" then
		stMnth = left(date(),4) & "-" & mnth
		If addSql <> "" Then addSql = addSql & " AND " End If 
		if keyset = "incomeDt" then 
			addSql = addSql & " A.incomeDt LIKE '" & stMnth & "%' "
		else
			addSql = addSql & " D." & keyset & " LIKE '" & stMnth & "%' "
		end if 		 
	end if 

	If addSql <> "" Then addSql = addSql & " AND " End If 
	addSql = addSql & " A.flag = 'Y' " 

	addSql = " WHERE " & addSql

	SQL = "SELECT A.seq, D.incSeq incSeq, RIGHT(D.actionDt,5) actionDt, P.partNm, RIGHT(D.bankDt,5) bankDt, ISNULL(A.restAmount,0) restAmount, ISNULL(D.amount,0) incAmount, B.accountNm, A.income, C.company, A.amount, A.orgAmount, A.tax, RIGHT(A.incomeDt,8) incomeDt, A.memo FROM tblIncome A " & _
		  " LEFT JOIN (SELECT * FROM tblIncResult WHERE flag='Y') D ON A.seq=D.incCd " & _
		  "	LEFT JOIN tblAccount B ON A.accountCd=B.accountCd " & _
		  "	LEFT JOIN (SELECT itemNm partNm, itemCd FROM tblComCode WHERE groupCd='0005' AND flag='Y') P ON A.part=P.itemCd " & _
		  " LEFT JOIN tblCompany C ON A.compCd=C.compCd " & addSql & _
		  " ORDER BY A.incomeDt DESC" 

	If xMode="debug" Then 
		Call showDebug(SQLTitle,SQL) 
	End If 

	Set Rs=Server.CreateObject("ADODB.RecordSet")
	Rs.open SQL, DbCon, 1
	
	Response.write "<Income>" & vbcrlf

	If Rs.eof Or Rs.bof Then 
	Else 
		Do Until Rs.eof Or Rs.bof
		
			If rs("memo") <> "" Then 
				memo = Left(rs("memo"),5) & "..."
			End If 
			Response.write "	<IncomeList>" & vbcrlf
				Call mkXMLNode("seq", rs("seq"), 2)
				Call mkXMLNode("incSeq", rs("incSeq"), 2)
				Call mkXMLNode("actionDt", rs("actionDt"), 2)
				Call mkXMLNode("bankDt", rs("bankDt"), 2)
				Call mkXMLNode("partNm", rs("partNm"), 2)
				Call mkXMLNode("restAmount", rs("restAmount"), 2)
				Call mkXMLNode("incAmount", FormatNumber(rs("incAmount"),0), 2)
				Call mkXMLNode("accountNm", rs("accountNm"), 2)
				Call mkXMLNode("income", rs("income"), 2)
				Call mkXMLNode("company", rs("company"), 2)
				Call mkXMLNode("amount", FormatNumber(rs("amount"),0), 2)
				Call mkXMLNode("orgAmount", FormatNumber(rs("orgAmount"),0), 2)
				Call mkXMLNode("tax", FormatNumber(rs("tax"),0), 2)
				Call mkXMLNode("incomeDt", rs("incomeDt"), 2)
				Call mkXMLNode("memo", memo, 2)
			Response.write "	</IncomeList>" & vbcrlf

		Rs.movenext
		Loop 
	End If
	Response.write "</Income>" & vbcrlf
'	Call rsWithXML("Save OK!")
%>